{include /common/header}
<script>
    var M={};
    $(function() {
        M.status = function(path){
            $.ajax({
                url: '{:\mylib\Route::buildUrl('/admin/plugin/status')}',
                type: 'POST',
                dataType: 'json',
                data: {
                    path:path
                },
                success:function(res){
                    alert(res.message);
                    if (res.code) {
                        location.reload();
                    }
                },
                error:function(res){
                    alert('系统繁忙');
                }
            });
        }
        M.install = function(path){
            if (confirm('确定安装吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/plugin/install')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        path:path
                    },
                    success:function(res){
                        alert(res.message);
                        if (res.code) {
                            location.reload();
                        }
                    },
                    error:function(res){
                        alert('系统繁忙');
                    }
                });
            }
        }
        M.uninstall = function(path){
            if (confirm('确定卸载吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/plugin/uninstall')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        path:path
                    },
                    success:function(res){
                        alert(res.message);
                        if (res.code) {
                            location.reload();
                        }
                    },
                    error:function(res){
                        alert('系统繁忙');
                    }
                });
            }
        }
    });
</script>
<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>文件夹</th>
                <th>名称</th>
                <th>简介</th>
                <th>版本</th>
                <th>作者</th>
                <th>卸载/安装</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {foreach $plugins as $path => $v}
            <tr>
                <td>{$path}</td>
                <td>{$v.name?:'-'}</td>
                <td>{$v.description?:'-'}</td>
                <td>{$v.version?:'-'}</td>
                <td>
                    {if isset($v['weburl']) && $v['weburl']}
                        <a href="{$v.weburl?:'#'}" target="_blank">{$v.author?:'联系作者'}</a>
                    {else}
                        {$v.author?:'-'}
                    {/if}
                </td>
                {if isset($myplugs[$path])}
                    <td>
                        <a href="#" onclick="M.uninstall('{$path}')">卸载</a>
                    </td>
                    <td>
                        {if isset($myplugs[$path]['status']) && $myplugs[$path]['status']}
                            <a href="#" onclick="M.status('{$path}')">已启用</a>
                        {else}
                            <a href="#" onclick="M.status('{$path}')">未启用</a>
                        {/if}
                    </td>
                    <td>
                        {if isset($v['manager_url']) && $v['manager_url']}
                            <a href="{$v.manager_url}">管理</a>
                        {else}
                            -
                        {/if}
                    </td>
                {else}
                    <td>
                        <a href="#" onclick="M.install('{$path}')">安装</a>
                    </td>
                    <td> - </td>
                    <td> - </td>
                {/if}
            </tr>
            {/foreach}
        </tbody>
    </table>
</div>
{include /common/footer}